#ifndef EM80_BATTERY_HPP
#define EM80_BATTERY_HPP

#include "../packet_base.hpp"
#include "../payload_headers.hpp"
#include "../em80_payload_factory.h"
#include "../../v8stdint.h"

#include <memory>

namespace em80_driver
{

class Battery : public EM80PayloadBase
{
public:
    Battery(const EM80PacketPtr &packet) : EM80PayloadBase(packet, "Battery", false, 4) {}

    struct Data
    {
        uint8_t status;
        uint8_t capacity;    // unit: %
        uint16_t voltage;    // unit: 0.1A

    };

    struct BatteryEvent
    {
        enum State
        {
            Charging = 0,
            Charged,
            OutOfService
        };
    };

    Data data;

    ~Battery() {}

    //not to be used directly by external source
    bool serialize()
    {
        // //TODO : is it directly control the raw data
        // std::shared_ptr<Buffer> byteStream = std::make_shared<Buffer>(packet->payload(), packet->packet().second);
        // buildBytes(static_cast<uint8_t>(Header::Battery), *byteStream);
        // buildBytes(static_cast<uint8_t>(length), *byteStream);
        // buildBytes(data.status, *byteStream);
        // buildBytes(data.capacity, *byteStream);
        // buildBytes(data.current, *byteStream);

        return true;
    }


    bool deserialize()
    {
        std::vector<uint8_t> byteStream;

        byteStream.assign(packet->payload(), packet->payload() + static_cast<uint32_t>(length) + 2);


        //TODO: check them
        uint8_t header_id, length_packed;
        buildVariable(header_id, byteStream);
        buildVariable(length_packed, byteStream);
        if(header_id != Header::Battery) return false;
        if(length_packed != length) return false;

        buildVariable(data.status, byteStream);
        buildVariable(data.capacity, byteStream);
        buildVariable(data.voltage, byteStream);


        return true;
    }
};



} // namespace em80_driver

#endif /* EM80_BATTERY_HPP*/
